/**
 * 版权所有(C) COVISINT 2015-2025
 * Copyright 2015-2025 COVISINT
 * 创建日期：Jun 29, 20171:44:03 PM
 * 创建人：yyang
 */
package com.wechat.framework.support;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wechat.framework.interceptor.OAuthRequired;

public abstract class AuthorizationFrameworkSupport {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * 微信OAuth2认证
	 * @param httpRequest
	 * @param respon
	 * @return
	 * @throws Exception
	 */
	@OAuthRequired
	@RequestMapping("/authorization")
	public ModelAndView Authorization(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//TODO
		logger.info("OAuth2 Redirect Load UserId...");
		
		HttpSession session = request.getSession();
		String userId = (String) session.getAttribute("UserId");				
		logger.info("UserId = " + userId);
		
		//设置缓存操作
		if(null != userId && !"".equals(userId)){
			this.setCacheOperation(userId);
		}
		
		//取得redirect的URL
		String redirectURL = this.setRedirectURL();
		
		return new ModelAndView("redirect:" + redirectURL);
	}
	
	/**
	 * 设置重定向地址
	 * @return
	 */
	public abstract String setRedirectURL();
	
	/**
	 * 设置缓存操作
	 * @return
	 */
	public abstract String setCacheOperation(String userId);
	
}
